package kalambury.srv;

import kalambury.srv.packets.Packet;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 06.11.12
 * Time: 17:34
 * To change this template use File | Settings | File Templates.
 */

/**
 * klasa reprezentująca użytkownika w grze
 */
public class UserSocket {
    public UserSocket(Socket s, ObjectInputStream ois, ObjectOutputStream oos, String name)
    {
        socket=s;
        in=ois;
        out=oos;
        this.name = name;
        status = PlayerStatus.Observer;
    }

    /**
     * socket gracza
     */
    public Socket socket;
    /**
     * strumień nadawczy gracza
     */
    public ObjectOutputStream out;
    /**
     * strumień odbiorczy gracza
     */
    public ObjectInputStream in;
    /**
     * nazwa gracza
     */
    public String name;
    /**
     * stan gracza
     */
    public PlayerStatus status;

    /**
     * wysyła pakiet do gracza
     * @param p pakiet do wysłania
     * @throws Exception
     */
    public synchronized void sendPacket(Packet p) throws Exception {
        out.writeObject(p);
    }
}
